#!/usr/bin/perl
# file: redirect.pl

print "Redirecting STDOUT!\n";
open (SAVEOUT, ">&STDOUT");
open (STDOUT, ">test.txt") or die "Cannot open test.txt!";

print "STDOUT is redirected!\n";
system "date";

open(STDOUT, ">&SAVEOUT");
print "STDOUT restored!\n";